<?php

	if ( !defined( "VISITOR_TRACKER_COOKIE" ) )
		define( "VISITOR_TRACKER_COOKIE", "KONSOLIDATETRACKER" );

	/*
	 *            ________ ___
	 *           /   /   /\  /\       Konsolidate
	 *      ____/   /___/  \/  \
	 *     /           /\      /      http://konsolidate.klof.net
	 *    /___     ___/  \    /
	 *    \  /   /\   \  /    \       Class:  CoreDevUserTracker
	 *     \/___/  \___\/      \      Tier:   CoreDev
	 *      \   \  /\   \  /\  /      Module: User/Tracker
	 *       \___\/  \___\/  \/
	 *         \          \  /        $Rev: 46 $
	 *          \___    ___\/         $Author: john $
	 *              \   \  /          $Date: 2007-12-14 14:27:49 +0100 (Fri, 14 Dec 2007) $
	 *               \___\/
	 */


	/**
	 *  User tracking
	 *  @name    CoreDevUserTracker
	 *  @type    class
	 *  @package Konsolidate
	 *  @author  John Beitler <john.beitler@advance.nl>
	 */
	class CoreDevUserTracker extends CoreUserTracker
	{
		/**
		 *  The visitor id
		 *  @name    id
		 *  @type    int
		 *  @access  public
		 */
		public $id;

		/**
		 *  The visitor code
		 *  @name    code
		 *  @type    string (32 characters)
		 *  @access  public
		 */
		public $code;

		/**
		 *  The unix timestamp of the last visit (pageview)
		 *  @name    last
		 *  @type    int (unix timestamp)
		 *  @access  public
		 */
		public $last;


		public function __construct( &$oParent )
		{
			parent::__construct( $oParent );
			$this->id         = null;
			$this->code       = null;
			$this->last       = null;
		}

		/**
		 *  Write the cookie to the user agent
		 *  @name    updateVisit
		 *  @type    method
		 *  @access  public
		 *  @returns bool
		 *  @syntax  Object->updateVisit();
		 */
		public function updateVisit()
		{
			$sQuery  = "UPDATE usertracker
						   SET ustlastvisitts=NOW()
						 WHERE ustid={$this->id}";
			$oResult = $this->call( "/DB/query", $sQuery );
			if ( is_object( $oResult ) && $oResult->errno <= 0 )
			{
				error_log( __METHOD__ . ' (' . __LINE__ . ') => storeCookie called by updateVisit() ' );
				return $this->storeCookie( false );
			}
			return false;
		}

		/**
		 *  Login
		 *  @name    login
		 *  @type    method
		 *  @access  public
		 *  @returns bool
		 *  @syntax  Object->login();
		 */
		public function login( $sCode=false, $bAutoLogin=true )
		{
			if ( $sCode !== false )
			{
				$this->code = $sCode;
				error_log( __METHOD__ . ' (' . __LINE__ . ') => storeCookie called by login() ' );
				return $this->storeCookie( true, $bAutoLogin );
			}
			return false;
		}
	}

?>